package com.jeasonzhao.report.vml.base;

import java.util.ArrayList;

import com.jeasonzhao.report.vml.exception.VMLException;


public class PolyLine extends Line
{
    ArrayList m_allPoints = null;
    public PolyLine()
    {
        this.setFilled(false);
    }

    protected String wrapHtmlAttrName(String str)
    {
        if(null != str && (str.equalsIgnoreCase("from") || str.equalsIgnoreCase("to")))
        {
            return null;
        }
        return super.wrapHtmlAttrName(str);
    }

    public PolyLine(Vector2D[] pts)
    {
        add(pts);
    }

    public void add(Vector2D pt)
    {
        if(null == pt)
        {
            return;
        }
        if(null == m_allPoints)
        {
            m_allPoints = new ArrayList();
        }
        m_allPoints.add(new Vector2D(pt));
    }

    public void add(Vector2D[] pts)
    {
        if(null == pts)
        {
            return;
        }
        if(null == m_allPoints)
        {
            m_allPoints = new ArrayList();
        }
        for(int n = 0;null != pts && n < pts.length;n++)
        {
            m_allPoints.add(new Vector2D(pts[n]));
        }
    }

    private String m_attr_Points = null;
    public boolean prepareHTML()
        throws VMLException
    {
        if(null == m_allPoints || m_allPoints.size() < 1)
        {
            return false;
        }
        String str = "";
        for(int n = 0;null != m_allPoints && n < m_allPoints.size();n++)
        {
            Vector2D pt = (Vector2D) m_allPoints.get(n);
            if(str.length() > 0)
            {
                str += ",";
            }
            str += pt.getX() + "," + pt.getY();
        }
        m_attr_Points = str;
        return super.prepareHTML();
    }
}
